package com.yunshipei.ui.view;


import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.yunshipei.enterplorer.R;

public class YspBrowserFrameLayout extends FrameLayout {

    private int screenHeight = 0;

    public YspBrowserFrameLayout(Context context) {
        super(context);
    }

    public YspBrowserFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        screenHeight = getScreenSize(context)[1];
    }

    public YspBrowserFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int size = MeasureSpec.getSize(heightMeasureSpec);
        Log.d("size_:", screenHeight + "   " + size);
        if (screenHeight - size > 400) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec + getResources().getDimensionPixelOffset(R.dimen.browser_menu_bar));
        } else {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

    public int[] getScreenSize(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(outMetrics);
        return new int[]{outMetrics.widthPixels, outMetrics.heightPixels};
    }

}
